package com.weiaibenpao.demo.chislim.ui.activity.me;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.lib.WheelView;
import com.bumptech.glide.Glide;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.PictureFileUtils;
import com.orhanobut.logger.Logger;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager;
import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.api.Url;
import com.weiaibenpao.demo.chislim.base.BaseActivity;
import com.weiaibenpao.demo.chislim.bean.ImageInfo;
import com.weiaibenpao.demo.chislim.bean.UserBean;
import com.weiaibenpao.demo.chislim.bean.UserDataBean;
import com.weiaibenpao.demo.chislim.db.preferences.UserPreferences;
import com.weiaibenpao.demo.chislim.presenter.LoginPresenter;
import com.weiaibenpao.demo.chislim.ui.widget.CircleImage;
import com.weiaibenpao.demo.chislim.ui.widget.CustomTitleBar;
import com.weiaibenpao.demo.chislim.utils.Utils;
import com.weiaibenpao.demo.chislim.view.LoginView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.OkHttpClient;
import okhttp3.Request;

import static com.weiaibenpao.demo.chislim.db.preferences.UserPreferences.USER_AVATAR;
import static com.weiaibenpao.demo.chislim.db.preferences.UserPreferences.USER_BIRTH;
import static com.weiaibenpao.demo.chislim.db.preferences.UserPreferences.USER_HEIGHT;
import static com.weiaibenpao.demo.chislim.db.preferences.UserPreferences.USER_INTRO;
import static com.weiaibenpao.demo.chislim.db.preferences.UserPreferences.USER_NAME;
import static com.weiaibenpao.demo.chislim.db.preferences.UserPreferences.USER_SEX;
import static com.weiaibenpao.demo.chislim.db.preferences.UserPreferences.USER_WEIGHT;

public class UserInfoActivity extends BaseActivity<LoginView, LoginPresenter> implements LoginView {

    @BindView(R.id.userImage)
    CircleImage userImage;
    @BindView(R.id.userName)
    TextView userName;
    @BindView(R.id.userNameLayout)
    LinearLayout userNameLayout;
    @BindView(R.id.userSex)
    TextView userSex;
    @BindView(R.id.userSexLayout)
    LinearLayout userSexLayout;
    @BindView(R.id.userHeigh)
    TextView userHeigh;
    @BindView(R.id.userHeighLayout)
    LinearLayout userHeighLayout;
    @BindView(R.id.userWeight)
    TextView userWeight;
    @BindView(R.id.userWeightLayout)
    LinearLayout userWeightLayout;
    @BindView(R.id.userBirth)
    TextView userBirth;
    @BindView(R.id.userBirthLayout)
    LinearLayout userBirthLayout;
    @BindView(R.id.userSign)
    TextView userSign;
    @BindView(R.id.userSignLayout)
    LinearLayout userSignLayout;
    String date="1990-01-01";

    UserPreferences userPreferences;
//    private List<LocalMedia> selectList = new ArrayList<>();

    String TAG = "ljb";
    private AlertDialog dialog;
    /**
     * type==1修改昵称
     * type==2修改签名
     * type==3 头像
     * type==4 性别
     * type==5 体重
     * type==6 身高
     * type==7 生日
     */
    private int type = 1;
    private OkHttpClient client;
    //    private Request request;
    private String token;
    private final static int UP_SUCCESS = 12000;
    private String path;
    private String pathImg;

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 100:
                    if (!TextUtils.isEmpty(token)) {
                        uploadImageToQiNiu();
                    }
                    break;
                case UP_SUCCESS:
                    mPresenter.upDataInfo(userId, pathImg, "", "", 0, 0, "", "");

            }
        }
    };
    private int num1;
    private OptionsPickerView pvOptions;
    private List<String> sexList;
    private int userId;
    private Request.Builder request;

    @BindView(R.id.myTitle)
    CustomTitleBar myTitle;

    @Override
    public int setLayoutResourceID() {
        return R.layout.activity_user_info;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        EventBus.getDefault().register(this);
        userPreferences = UserPreferences.getInstance();
        userId = userPreferences.getInt(UserPreferences.USER_ID);



        sexList = new ArrayList<>();
        initView();
        /**
         * 七牛
         */
        //发送七牛请求
        client = new OkHttpClient();
        request = new Request.Builder().url(Url.TOKEN_URL).get();
    }

    public void initView() {
        Glide.with(this)
                .load(userPreferences.getString(USER_AVATAR))
                .into(userImage);
        userName.setText(userPreferences.getString(USER_NAME));
        userSex.setText(userPreferences.getString(USER_SEX));
        userHeigh.setText(userPreferences.getInt(USER_HEIGHT) + "cm");
        userWeight.setText(userPreferences.getFloat(USER_WEIGHT) + "kg");
        userBirth.setText(userPreferences.getString(USER_BIRTH));
        userSign.setText(userPreferences.getString(USER_INTRO));
        sexList.add("男");
        sexList.add("女");
    }

    @OnClick({R.id.userImageLayout, R.id.userNameLayout,
            R.id.userSexLayout, R.id.userHeighLayout, R.id.userWeightLayout, R.id.userBirthLayout, R.id.userSignLayout,R.id.left_image})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_image:
               finish();
                break;
            case R.id.userImageLayout:
                //跟换头像
                type = 3;
                upUserImg();
                break;
            case R.id.userNameLayout:
                //修改昵称
                type = 1;

                NameSignChangeActivity.startSelf(this, type);
                break;
            case R.id.userSexLayout:
                //修改性别
                type = 4;
                showPickerView();
                break;
            case R.id.userHeighLayout:
                //修改身高
                type = 6;
                createBottomSheetDialog(type);
                break;
            case R.id.userWeightLayout:
                //修改体重
                type = 5;
                createBottomSheetDialog(type);
                break;
            case R.id.userBirthLayout:
                //修改生日
                type = 7;
                createBottomSheetDialog(type);
                break;
            case R.id.userSignLayout:
                //修改签名
                type = 2;
                NameSignChangeActivity.startSelf(this, type);

                break;
        }
    }

    /**
     * 性别
     */
    private void showPickerView() {
        pvOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                num1 = options1;
                userSex.setText(sexList.get(options1));
                mPresenter.upDataInfo(userId, "", "", sexList.get(options1), 0, 0, "", "");
            }
        }).setTitleText(" ")
                .setDividerColor(Color.BLACK)
                .setOutSideCancelable(true)
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .setSubmitColor(Color.parseColor("#333333"))//确定按钮文字颜色
                .setCancelColor(Color.parseColor("#333333"))//取消按钮文字颜色
                .setLineSpacingMultiplier(3.0f)
                .setSelectOptions(num1)
                .setDividerType(WheelView.DividerType.FILL)
                .setDividerColor(Color.parseColor("#FFFFFF"))
                .setTitleBgColor(Color.parseColor("#FFFFFF"))
                .build();

        /*pvOptions.setPicker(options1Items);//一级选择器
        pvOptions.setPicker(options1Items, options2Items);//二级选择器*/
        pvOptions.setPicker(sexList);
        pvOptions.show();
    }


    /**
     * 头像
     */
    private void upUserImg() {
        checkPerMissions();
    }

    private void startCamera(boolean isOpenCamera) {

        // 进入相册 以下是例子：用不到的api可以不写
        if (isOpenCamera) {//打开相机
            // 单独拍照
            PictureSelector.create(UserInfoActivity.this)
                    .openCamera(PictureMimeType.ofImage())// 单独拍照，也可录像或也可音频 看你传入的类型是图片or视频
                    .maxSelectNum(1)
                    .enableCrop(true)// 是否裁剪 true or false
                    .freeStyleCropEnabled(true)// 裁剪框是否可拖拽 true or false
                    .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
                    .imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                    .withAspectRatio(1, 1)// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
//                .glideOverride(160, 160)// glide 加载宽高，越小图片列表越流畅，但会影响列表图片浏览的清晰度
//                .selectionMedia()// 是否传入已选图片
                    .rotateEnabled(false) // 裁剪是否可旋转图片 true or false
                    .forResult(PictureConfig.CHOOSE_REQUEST);// 最大图片选择数量
        } else {//打开相册
            PictureSelector.create(UserInfoActivity.this)
                    .openGallery(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                    .maxSelectNum(1)// 最大图片选择数量 int
                    .isCamera(true)// 是否显示拍照按钮 true or false
                    .enableCrop(true)// 是否裁剪 true or false
                    .freeStyleCropEnabled(true)// 裁剪框是否可拖拽 true or false
                    .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
                    .imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                    .withAspectRatio(1, 1)// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
//                .glideOverride(160, 160)// glide 加载宽高，越小图片列表越流畅，但会影响列表图片浏览的清晰度
//                .selectionMedia()// 是否传入已选图片
                    .rotateEnabled(false) // 裁剪是否可旋转图片 true or false

                    .rotateEnabled(true) // 裁剪是否可旋转图片 true or false
                    .isCamera(false)// 是否显示拍照按钮 true or false
                    .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case 123:
                    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        // 检查该权限是否已经获取
                        int i = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION);
                        // 权限是否已经 授权 GRANTED---授权  DINIED---拒绝
                        if (i != PackageManager.PERMISSION_GRANTED) {
                            // 提示用户应该去应用设置界面手动开启权限
                            showDialogTipUserGoToAppSetting();
                        } else {
                            if (dialog != null && dialog.isShowing()) {
                                dialog.dismiss();
                            }

                        }
                        break;
                    }
                case PictureConfig.CHOOSE_REQUEST:
                    // 图片选择结果回调
                    List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                    LocalMedia localMedia = selectList.get(0);
                    if (localMedia.isCut()) {
                        path = localMedia.getCutPath();

                    } else {
                        path = localMedia.getPath();
                    }
                    getToken();
                    Glide.with(this).load(path).into(userImage);

//                    userPreferences.getInt(UserPreferences.USER_ID)
                    // 例如 LocalMedia 里面返回三种path
                    // 1.media.getPath(); 为原图path
                    // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true
                    // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true
                    // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的

                    break;
            }
        }

    }

    private void getToken() {
        //发送七牛请求
//        builder.build();

        client.newCall(request.build()).enqueue(new okhttp3.Callback() {
            @Override
            public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException {

                token = response.body().string();
                Logger.e("token==" + token);
                mHandler.sendEmptyMessage(100);
            }

            @Override
            public void onFailure(okhttp3.Call call, IOException e) {
//                dialog.dismiss();
                Toast.makeText(UserInfoActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void uploadImageToQiNiu() {
        new Thread() {
            public void run() {
                // 图片上传到七牛 重用 uploadManager。一般地，只需要创建一个 uploadManager 对象
                UploadManager uploadManager = new UploadManager();
                uploadManager.put(path, null, token, new UpCompletionHandler() {
                    @Override
                    public void complete(String key, ResponseInfo info, JSONObject res) {
                        // res 包含hash、key等信息，具体字段取决于上传策略的设置。
                        if (info.isOK()) {
                            try {
                                // 七牛返回的文件名
                                pathImg = Url.PIC_URL + res.getString("key");
//                            qiNiuList.add(upImg);//将七牛返回图片的文件名添加到list集合
                                //list集合中图片上传完成后，发送handler消息回主线程进行其他操作
//                            if (qiNiuList.size() == selectList.size()) {
//                            Message obtain = Message.obtain();
//                            obtain.obj = upImg;
//                            obtain.what = UP_SUCCESS;
                                mHandler.sendEmptyMessage(UP_SUCCESS);
//                            }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else if (info.isServerError()) {
                            Toast.makeText(UserInfoActivity.this, "服务器异常，请稍后再试", Toast.LENGTH_SHORT).show();
                        }
                    }
                }, null);
            }
        }.start();
    }

    /**
     * 权限检查
     *
     * @param
     */
    public void checkPerMissions() {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            //申请WRITE_EXTERNAL_STORAGE权限
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1);
        } else {
            createBottomSheetDialog(3);
        }
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            createBottomSheetDialog(3);
        } else {
            showDialogTipUserGoToAppSetting();
        }
    }

    // 提示用户去应用设置界面手动开启权限
    private void showDialogTipUserGoToAppSetting() {
        String set = "请在-应用设置-权限管理\n允许东极圈使用相机权限，确保该功能的正常使用";
        dialog = new AlertDialog.Builder(this)
                .setTitle("相机权限不可用")
                .setMessage(set)
                .setPositiveButton("立即开启", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 跳转到应用设置界面
                        goToAppSetting();
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        Toast.makeText(UserInfoActivity.this, "请在应用管理中打开相关访问权限，确保该功能的正常使用", Toast.LENGTH_SHORT).show();
                    }
                }).setCancelable(false).show();
    }

    // 跳转到当前应用的设置界面
    private void goToAppSetting() {
        Intent intent = new Intent();

        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts("package", getPackageName(), null);
        intent.setData(uri);

        startActivityForResult(intent, 123);
    }

    /**
     * 底部滑动显示
     *
     * @param n
     * type==1修改昵称
     * type==2修改签名
     * type==3 头像
     * type==4 性别
     * type==5 体重
     * type==6 身高
     * type==7 生日
     */
    private BottomSheetDialog mBottomSheetDialog;

    private void createBottomSheetDialog(final int n) {
        //new 一个BottomSheetDialog对象
        mBottomSheetDialog = new BottomSheetDialog(this);
        //获取要添加到BottomSheetDialog中的布局view
        View view = createBottomSheetDialogContent(n);

        //将布局添加到BottomSheetDialog中
        mBottomSheetDialog.setContentView(view);

        //显示
        mBottomSheetDialog.show();
    }

    /**
     * type==1修改昵称
     * type==2修改签名
     * type==3 头像
     * type==4 性别
     * type==5 体重
     * type==6 身高
     * type==7 生日
     */
    TextView allWeight;

    private View createBottomSheetDialogContent(final int n) {
        View view = null;
        switch (n) {
            case 5:
            case 6:
                if (view == null)
                    view = LayoutInflater.from(this).inflate(R.layout.layout_height_weight, null, false);
                final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekBar);

                TextView cancel = (TextView) view.findViewById(R.id.cancel);
                TextView commit = (TextView) view.findViewById(R.id.commit);
                allWeight = (TextView) view.findViewById(R.id.allWeight);

                if (n == 5) {   //体重
                    //设置体重最大值
                    seekBar.setMax(150);
                    //设置弹出上滑框后的初始值
                    seekBar.setProgress(Math.round(userPreferences.getFloat(USER_WEIGHT)));
                    allWeight.setText(userPreferences.getFloat(USER_WEIGHT) + "kg");
                } else if (n == 6) {     //身高
                    //设置身高最大值
                    seekBar.setMax(230);
                    //设置弹出上滑框后的初始值
                    allWeight.setText(userPreferences.getInt(USER_HEIGHT) + "cm");
                    seekBar.setProgress(userPreferences.getInt(USER_HEIGHT));
                }

                cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mBottomSheetDialog.dismiss();
                    }
                });
                commit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mBottomSheetDialog.dismiss();
                        if (n == 5) {      //体重
                            //todo  滑块滑动
                            //设置数据
                            String weight = Utils.decimalFormat(seekBar.getProgress());
                            mPresenter.upDataInfo(userId, "", "", "", 0, Float.parseFloat(weight), "", "");
//                            mPresenter.updateUserWeigh(userPreferences.getInt(USER_ID),seekBar.getProgress()+"");
//                            userPreferences.putFloat(USER_WEIGHT, seekBar.getProgress());

                        } else if (n == 6) {
                            //设置数据
                            mPresenter.upDataInfo(userId, "", "", "", seekBar.getProgress(), 0, "", "");

//                            mPresenter.updateUserHeight(userPreferences.getInt(USER_ID),seekBar.getProgress()+"");
//                            userPreferences.putInt(USER_HEIGHT, seekBar.getProgress());
                        }
                    }
                });

                seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                        Log.i("滑块", "滑块 " + i);
                        if (n == 5) {    //体重
                            //todo  滑块滑动
                            //UserDataBean.getUserBean().userWeight = (float) (i);
                            userWeight.setText((i) + "kg");
                            allWeight.setText((i) + "kg");

                        } else if (n == 6) {
                            //UserDataBean.getUserBean().userHeigh = (i);
                            userHeigh.setText((i) + "cm");
                            allWeight.setText((i) + "cm");
                        }
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {

                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {

                    }
                });
                break;
            case 7:
                view = LayoutInflater.from(this).inflate(R.layout.date_layout, null, false);
                view.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mBottomSheetDialog.dismiss();
                    }
                });
                view.findViewById(R.id.myOK).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //   UserDataBean.getUserBean().userBirth = date;
                        userBirth.setText(date);
                        mBottomSheetDialog.dismiss();
                        mPresenter.upDataInfo(userId, "", "", "", 0, 0, date, "");

//                        mPresenter.updateUserBirth(userPreferences.getInt(USER_ID),date);
                    }
                });
                final DatePicker datePicker = (DatePicker) view.findViewById(R.id.datePicker);
                datePicker.setDrawingCacheBackgroundColor(getResources().getColor(R.color.colorAccent));
                //初始化DatePicker组件，初始化时指定监听器
                datePicker.init(1990, 01, 01, new DatePicker.OnDateChangedListener() {
                    @Override
                    public void onDateChanged(DatePicker arg0, int year, int month, int day) {
                        // 显示当前日期、时间
                        month = month + 1;
                        date = year + "-" + month + "-" + day;
                    }
                });
                break;
            case 3:
                view = LayoutInflater.from(this).inflate(R.layout.pop_window_layout, null, false);
                view.findViewById(R.id.tv_camera).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mBottomSheetDialog.dismiss();
                        startCamera(true);
                    }
                });
                view.findViewById(R.id.tv_photo).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mBottomSheetDialog.dismiss();
                        startCamera(false);

                    }
                });
                view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mBottomSheetDialog.dismiss();
                    }
                });
                break;
        }
        return view;
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(UserBean infoBean) {
        if (type == 1) {
            userPreferences.putString(UserPreferences.USER_NAME, infoBean.getUserName());
            userName.setText(infoBean.getUserName());
        } else if (type == 2) {
            userPreferences.putString(UserPreferences.USER_INTRO, infoBean.getUserIntru());
            userSign.setText(infoBean.getUserIntru());
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    @Override
    public LoginPresenter initPresenter() {
        return new LoginPresenter();
    }


    @Override
    public void upDataInfoSuccess(UserBean info) {
        /**
         * type==1修改昵称
         * type==2修改签名
         * type==3 头像
         * type==4 性别
         * type==5 体重
         * type==6 身高
         * type==7 生日
         */
        if (type == 3) {
            EventBus.getDefault().post(new ImageInfo(info.getUserImage()));
            userPreferences.putString(USER_AVATAR, info.getUserImage());
            //包括裁剪和压缩后的缓存，要在上传成功后调用，注意：需要系统sd卡权限
            PictureFileUtils.deleteCacheDirFile(UserInfoActivity.this);
        } else if (type == 4) {
            userPreferences.putString(USER_SEX, info.getUserSex());

        } else if (type == 5) {
            userPreferences.putFloat(USER_WEIGHT, info.getUserWeight());

        } else if (type == 6) {
            userPreferences.putInt(USER_HEIGHT, info.getUserHeigh());

        } else if (type == 7) {
            userPreferences.putString(USER_BIRTH, info.getUserBirth());

        }
    }

    @Override
    public void loginSuccess(UserDataBean userDataBean) {

    }


    @Override
    public void seedSuccess(String str) {

    }



}
